/**
 * 
 * @authors supmain (mtingfeng@gmail.com)
 * @date    2014-12-12 17:18:02
 * @update  2014-12-12 17:18:02
 * @for webapp.html
 * @version $Id$
 */
var BST = BST || {};
BST.search = {
	init: function(){
		var that = this;
		//搜索
		that.search();
	},
	search: function(){
		var $search = $("#search"),
			$resultbox = $("#searchingbox"),
			$main = $(".main");
		$search.on('input', function(event) {
			var $this = $(this),
			    value = $.trim($this.val());
			if (value == '') {
				$resultbox.html('');
				$main.show();
				return false;
			};
			$.ajax({
				url: 'search.txt',
				type: 'post',
				dataType: 'json',
				data: {search: value},
				success: function (data) {
					var preHTML = "<ul>"
					$.each(data.items,function(index,val){
                       var temple = '<li><a href="javascript:void(0);">'+val+'</a></li>';

                       preHTML += temple;
					});
					preHTML += "</ul>";
					$resultbox.html(preHTML);
					$main.hide();
				},
				error: function(xhr, type){
					$resultbox.html('');
					$main.show();
					BST.dialog.tip("网络错误！");
				}
			});
			return false;
		});
	}
};
$(function(){
	BST.search.init();
});